package com.ruoyi.wq.service.impl;

import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wq.mapper.WqAdUserLogMapper;
import com.ruoyi.wq.domain.WqAdUserLog;
import com.ruoyi.wq.service.IWqAdUserLogService;

import cn.hutool.core.date.DateUtil;

/**
 * 用户广告日志Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-08-20
 */
@Service
public class WqAdUserLogServiceImpl extends ServiceImpl<WqAdUserLogMapper, WqAdUserLog> implements IWqAdUserLogService {

    @Autowired
    private WqAdUserLogMapper wqAdUserLogMapper;

    /**
     * 查询用户广告日志
     * 
     * @param id 用户广告日志主键
     * @return 用户广告日志
     */
    @Override
    public WqAdUserLog selectWqAdUserLogById(String id)
    {
        return wqAdUserLogMapper.selectWqAdUserLogById(id);
    }

    /**
     * 查询用户广告日志列表
     * 
     * @param wqAdUserLog 用户广告日志
     * @return 用户广告日志
     */
    @Override
    public List<WqAdUserLog> selectWqAdUserLogList(WqAdUserLog wqAdUserLog)
    {
        return wqAdUserLogMapper.selectWqAdUserLogList(wqAdUserLog);
    }

    /**
     * 新增用户广告日志
     * 
     * @param wqAdUserLog 用户广告日志
     * @return 结果
     */
    @Override
    public int insertWqAdUserLog(WqAdUserLog wqAdUserLog)
    {
        wqAdUserLog.setCreateTime(DateUtils.getNowDate());
        return wqAdUserLogMapper.insertWqAdUserLog(wqAdUserLog);
    }

    /**
     * 修改用户广告日志
     * 
     * @param wqAdUserLog 用户广告日志
     * @return 结果
     */
    @Override
    public int updateWqAdUserLog(WqAdUserLog wqAdUserLog)
    {
        wqAdUserLog.setUpdateTime(DateUtils.getNowDate());
        return wqAdUserLogMapper.updateWqAdUserLog(wqAdUserLog);
    }

    /**
     * 批量删除用户广告日志
     * 
     * @param ids 需要删除的用户广告日志主键
     * @return 结果
     */
    @Override
    public int deleteWqAdUserLogByIds(String[] ids)
    {
        return wqAdUserLogMapper.deleteWqAdUserLogByIds(ids);
    }

    /**
     * 删除用户广告日志信息
     * 
     * @param id 用户广告日志主键
     * @return 结果
     */
    @Override
    public int deleteWqAdUserLogById(String id)
    {
        return wqAdUserLogMapper.deleteWqAdUserLogById(id);
    }

	@Override
	public Integer getAdNumByOpenId(String appId, String openId) {
		QueryWrapper<WqAdUserLog> qw = new QueryWrapper<>();
		WqAdUserLog entity = new WqAdUserLog();
		entity.setAppId(appId);
		entity.setOpenId(openId);
		entity.setRemark(DateUtil.formatDate(new Date()));
		qw.setEntity(entity);
		return wqAdUserLogMapper.selectCount(qw);
	}
}
